#include <iostream>
using namespace std;

class Point
{
private:
    Point(int x, int y);
public:
    int m_x;
    int m_y;
    Point(/* args */);
    ~Point();
};

/*类-基类 */
class Person
{
public:
    /*跑*/
    virtual void run()
    {
        cout << "Person::run()" << endl;
    }

public:
    /*姓名*/
    char m_name[20];
    /*年龄*/
    int m_age;
};

class Student : public Person
{
public:
    /*跑*/
    virtual void run()
    {
        cout << "Student::run()" << endl;
    }

public:
    /*学号*/
    int m_id;
};

int testFunc(int val)
{
    cout << "val:" << val << endl;
    return 0;
}

int main()
{
#if 0
    /*c语言的强制转换*/
    char *str = (char *)malloc(sizeof(char) * 50);

    int val = 53.78;
    printf("val =%d\n", val);
    char *ptr = "hello world";
    cout << "ptr:" << ptr << endl;

    const charptr2 = ptr;
#endif

#if 0
    /*const cast 去掉const属性。*/
    const Point *p1 = new Point(10, 100);
    

    /*将const类型 转换成非const类型。*/
    const Point Point *p2 = const cast<Point *>(p1);
    p2->m x = 200;
    p2->m y = 200;
#endif

#if 0
    /*dynamic cast 一般用于多态类型的转换*/
    Person *p1 = new Person;
    p1->run();

    /*父类指针指向子类对象，虚函数*/
    Person *p2 = new Student;
    p2->run();

    Student *stu1 = new Student();
    stu1->run();

    // /*不允许使用子类指针指向父类对象,不然会有访问越界的问题 */
    // Student *stu2 = new Person();
    // stu2->m_id

    Student *stu2 = dynamic_cast<Student *>(p1);    //NULL
    /*
        (gdb)p stu2
        $1 =(Student *)0x0
    */

    cout << "id:" << stu2->m_id << endl;
#endif

#if 0
    /*
        static_cast
        1.对比dynamic cast，缺乏运行时安全检测.
        2.常用于基于数据类型的转换，非const转成const类型
        3.使用类型较广
    */
    char*str=static_cast<char*>(malloc(sizeof(char)*100));
    const char*ptr=static_cast<const char*>(str);
#endif

#if 1

    /*reinterpret_cast.*/
    /*
        属于是比较底层的转换，没有任何类型检查和格式转换
        一般用于指针的转换，将指针转换成其他类型。
    */
    int *p = reinterpret_cast<int *>(100);

    // int num = reinterpret cast<int>(p);
    cout << "p:" << p << endl;

    int *ptr = reinterpret_cast<int *>((Person::run));
    cout << "ptr:" << ptr << endl;

    testFunc(10);
#endif

    return 0;
}
